<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/18
 * Time: 9:45
 */

namespace Home\Controller;

use \Think\Controller;
use \Tools\AuthController;
class OrdergoodsController extends AuthController
{
    //设置结算点
    function BalanceTime()
    {
        $end_time = D('ssg_order_settlementtime');

        if (!empty($_POST)) {
            $data['settlementTime'] = $_POST["settime"];
            $data['editTime'] = date('Y-m-d H:i:s');
            if ($end_time->where("id=1")->save($data)) {
                echo "{\"result\":\"成功\"}";
            } else {
                echo "{\"result\":\"失败\"}";
            }
            return;
        }
        $this->assign("show", $end_time->find());
        $this->display();
    }

    //代付款订单
    function PaymentForOther()
    {
        $arr = $this->OrderList("orderStatus = 1",'ssg_order',$_POST["start_time"],$_POST['end_time']);
        $this->assign('page_list', $arr['page']->fpage());
        $this->assign('goods_list', $arr['result']);
        $this->display();
    }

    //显示订单列表
    function OrderList($operation, $which_table,$start_time,$end_time)
    {
        $page = new \Tools\paged();
        if (!empty($start_time) && !empty($end_time)) {
            $operation .= " and orderTime > '" . $start_time . "' and orderTime < '" . $end_time . "'";
        }
        $arr = $page->paged($which_table, 12, null, array(), $operation);
        return $arr;
    }

    //订单详情
    function Details()
    {
        if(!empty($_POST['orderNum'])){
            $ssg = M("ssg");
//            $details = $ssg->table(' ssg_address,ssg_order,ssg_account,ssg_order_produce,ssg_produce_images')->where("  ssg_produce_images.goodsCode = ssg_order_produce.goodsCode and  ssg_order_produce.specificationsId = ssg_produce_images.id and ssg_account.id = ssg_order.account_id AND ssg_order.account_id = ssg_address.account_id and ssg_address.id = ssg_order.addressId and ssg_order.orderNum = " . $_POST['orderNum'] . " AND ssg_order_produce.orderNum=" . $_POST['orderNum'])->find();
//            $this->ajaxReturn($details);
            $details = $ssg->table('ssg_address,ssg_order,ssg_account')->where("ssg_account.id = ssg_order.account_id AND ssg_order.account_id = ssg_address.account_id and ssg_address.id = ssg_order.addressId and orderNum = ". $_POST['orderNum'])->find();
            $this->ajaxReturn($details);
        }
    }

    //待发货订单
    function WaitingForDelivery()
    {
        $arr = $this->OrderList("orderStatus = 3",'ssg_order',$_POST["start_time"],$_POST['end_time']);
        $this->assign('page_list', $arr['page']->fpage());
        $this->assign('goods_list', $arr['result']);
        $this->display();
    }
    //已发货订单
    function Shipped()
    {
        $arr = $this->OrderList("orderStatus = 2",'ssg_order',$_POST["start_time"],$_POST['end_time']);
        $this->assign('page_list', $arr['page']->fpage());
        $this->assign('goods_list', $arr['result']);
        $this->display();
    }
    //已收货订单
    function ReceivedGoods(){
        $arr = $this->OrderList("orderStatus = 4",'ssg_order',$_POST["start_time"],$_POST['end_time']);
        $this->assign('page_list', $arr['page']->fpage());
        $this->assign('goods_list', $arr['result']);
        $this->display();
    }
}